package com.beauty.dressing.module.mine.activity;

import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;
import com.beauty.dressing.R;
import com.beauty.dressing.common.base.BaseActivity;
import com.beauty.dressing.common.bean.LeaseBean;
import com.beauty.dressing.common.bean.ReturnDetailInfoBean;
import com.beauty.dressing.common.bean.User;
import com.beauty.dressing.common.utils.Constants;
import com.beauty.dressing.logic.control.LBController;
import com.beauty.dressing.module.mine.persenter.MyLeaseControl;
import com.beauty.dressing.module.mine.persenter.MyLeasePresenter;
import com.beauty.dressing.rxandroid.api.ApiManager;
import com.xiaolanba.commonlib.fresco.FrescoUtil;

public class WithdrawalActivity extends BaseActivity {
    LeaseBean leaseBean;
    SimpleDraweeView image;
    TextView tv_lease_name, tv_static, tv_usedays_, tv_deposit,
            tv_cost_money, tv_price, tv_usedays, tv_return_money,
            title_txt;
    ReturnDetailInfoBean returnDetailInfoBean;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_withdrawal);
    }

    @Override
    public void findView() {
        findViewById(R.id.t_logistics_details).setOnClickListener(this);
        findViewById(R.id.left_img_btn).setOnClickListener(this);
        title_txt = findViewById(R.id.title_txt);
        title_txt.setText("商品详情");
        image = findViewById(R.id.image);
        tv_lease_name = findViewById(R.id.tv_lease_name);
        tv_static = findViewById(R.id.tv_static);
        tv_usedays_ = findViewById(R.id.tv_usedays_);
        tv_deposit = findViewById(R.id.tv_deposit);
        tv_cost_money = findViewById(R.id.tv_cost_money);
        tv_price = findViewById(R.id.tv_price);
        tv_usedays = findViewById(R.id.tv_usedays);
        tv_return_money = findViewById(R.id.tv_return_money);

    }

    @Override
    public void initData() {
        if (getIntent().getSerializableExtra(Constants.ACTIVITYDATA) != null) {
            leaseBean = (LeaseBean) getIntent().getSerializableExtra(Constants.ACTIVITYDATA);
            User user = LBController.getInstance().getCacheManager().getLoginUser();
            myLeasePresenter.returnDetail("3889f68da98eea80ffaf64ae8cae6ff4347a435c", 1, leaseBean.getId());
        } else if (getIntent().getIntExtra("order_id", -1) != -1) {
            myLeasePresenter.returnDetail("3889f68da98eea80ffaf64ae8cae6ff4347a435c", 1, getIntent().getIntExtra("order_id", -1));
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.left_img_btn:
                this.finish();
                break;
            case R.id.t_logistics_details:
                myLeasePresenter.getLogisticsInfo("3889f68da98eea80ffaf64ae8cae6ff4347a435c", 1, returnDetailInfoBean.getNumber());
                break;
        }
    }

    MyLeasePresenter myLeasePresenter = new MyLeasePresenter(new MyLeaseControl() {
        @Override
        public void onReturnDetail(boolean isSuccess, int code, String message, ReturnDetailInfoBean data) {
            super.onReturnDetail(isSuccess, code, message, data);
            returnDetailInfoBean = data;
            FrescoUtil.loadImage(image, ApiManager.HEAR_URL + data.getImage());
            tv_lease_name.setText(data.getLease_name());
            tv_static.setText(data.getStatus());
            tv_usedays_.setText(data.getUsedays() + "天");
            tv_deposit.setText(data.getDeposit());
            tv_cost_money.setText(data.getCost_money() + "元");
            tv_price.setText(data.getPrice() + "/天");
            tv_usedays.setText(data.getUsedays() + "天");
            tv_return_money.setText(data.getReturn_money() + "元");
        }

        @Override
        public void onGetLogisticsInfo(boolean isSuccess, int code, String message, Object data) {
            if (isSuccess) {
                Toast.makeText(context, data.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });

}
